﻿#region Namespace References

using System;
using DynConDevCorp.OpenArch.SmartData.Core;
using DynConDevCorp.OpenArch.SmartData.Interfaces;
using DynConDevCorp.OpenArch.SmartData.Interfaces.Attributes;
using DynConDevCorp.OpenArch.SmartData.Interfaces.EventArgClasses;

#endregion

namespace DynConDevCorp.OpenArch.SmartData.BillingDemo1.ApplicationBusinessObjects
{
    public class OrderDetail : SmartEntity
    {
        #region Constructors

        public OrderDetail()
        {
        }

        public OrderDetail(Guid EntityID)
            : base(EntityID)
        {
        }

        #endregion

        #region Public Instance Properties

        [AutoField]
        public ISmartField<String> Discount { get; private set; }

        [AutoField]
        public ISmartField<decimal> ExtendedPrice { get; private set; }

        [AutoField]
        public ISmartEntityLink<Order> Order { get; private set; }

        [AutoField]
        [Persist(IsXmlPersistable = false, IsDatabaseField = true, DatabaseFieldName = "OrderID")]
        public ISmartField<String> OrderNumber { get; private set; }

        [AutoField]
        public ISmartEntityLink<Product> Product { get; private set; }

        [AutoField]
        [Persist(IsXmlPersistable = false, IsDatabaseField = true, DatabaseFieldName = "ProductID")]
        public ISmartField<String> ProductNumber { get; private set; }

        [AutoField(ValueChanged = "CalculateExtendedValue")]
        public ISmartField<decimal> Quantity { get; private set; }

        [AutoField(ValueChanged = "CalculateExtendedValue")]
        public ISmartField<decimal> UnitPrice { get; private set; }

        #endregion

        #region Public Instance Methods

        public void CalculateExtendedValue(object sender, ValueChangedEventArgs<decimal> e)
        {
            if ((ExtendedPrice != null) && (Quantity != null) && (UnitPrice != null))
                ExtendedPrice.Value = Quantity.Value*UnitPrice.Value;
        }

        #endregion
    }
}